package com.yupi.yupicturebackend.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Getter
public enum SpaceRoleEnum {
    VIEWER("浏览者","viewer"),

    EDITOR("编辑者","editor"),

    ADMIN("管理员","admin");

    private final String text;
    private final String value;

    SpaceRoleEnum(String text, String value) {
        this.text = text;
        this.value = value;
    }

    /**
     * 根据value获取枚举
     * @param value
     * @return
     */
    public static SpaceRoleEnum getEnumByValue(String value) {
        for (SpaceRoleEnum spaceRoleEnum : SpaceRoleEnum.values()) {
            if (spaceRoleEnum.value.equals(value)) {
                return spaceRoleEnum;
            }
        }
        return null;
    }

    /**
     * 获取所有text
     * @return
     */
    public static List<String> getAllTexts() {
        return Arrays.stream(SpaceRoleEnum.values()).map(SpaceRoleEnum::getText).collect(Collectors.toList());
    }

    public static List<String> getAllValues() {
        return Arrays.stream(SpaceRoleEnum.values()).map(SpaceRoleEnum::getValue).collect(Collectors.toList());
    }
}
